package com.xxxx.server.controller;


import com.github.pagehelper.PageInfo;
import com.xxxx.server.pojo.Menu;
import com.xxxx.server.service.IMenuService;
import com.xzl.tool.util.RespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@Api(tags = "菜单管理MenuController")
@RequestMapping("/system/menu")
public class MenuController {

	@Autowired
	private IMenuService menuService;

	@ApiOperation("根据当前用户获取菜单")
	@GetMapping("")
	public RespBean getMenusByAdminId(){
		List<Menu> menusByAdminId = menuService.getMenusByAdminId();
		return RespBean.success(menusByAdminId);
	}

	@ApiOperation(value = "查询所有菜单")
	@GetMapping("/menus")
	public RespBean getMenusByRoleId(){
		return RespBean.success(menuService.getMenusAll());
	}

	@ApiOperation("新增菜单")
	@PostMapping("/insertMenu")
	public RespBean insertMenu(@Validated @RequestBody Menu menu){
		menuService.insertMenu(menu);
		return RespBean.success("新增成功！");
	}

	@ApiOperation("删除菜单")
	@ApiImplicitParam(name = "id",value = "菜单id",required = true,paramType = "query")
	@DeleteMapping("/delMenuById")
	public RespBean delMenuById(Integer id){
		menuService.delMenuById(id);
		return RespBean.success("删除成功！");
	}

	@ApiOperation("修改菜单")
	@PutMapping("/updMenu")
	public RespBean updMenu(@Validated @RequestBody Menu menu){
		menuService.updMenu(menu);
		return RespBean.success("修改成功！");
	}

	@GetMapping("/updMenuEnambled")
	@ApiOperation("修改菜单开启状态")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "menuId",value = "菜单id",required = true,paramType = "query"),
			@ApiImplicitParam(name = "enabled",value = "开启状态",required = true,paramType = "query")
	})
	public RespBean updMenuEnambled(Integer menuId,Boolean enabled){
		menuService.updMenuEnambled(menuId,enabled);
		if (enabled){
			return RespBean.success("已开启");
		}
		return RespBean.success("已关闭");
	}

}
